package model;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * compare Lists of Data according to one column
 * @author David, Rex
 */
@SuppressWarnings("rawtypes")
public class TableComparator implements Comparator<ArrayList<Comparable>> {
    private int myColumnIndex;
    private String myType;

    /**
     * construct the TableComparator
     * @param columnIndex index of the column which determines the order
     * @param compareType type of data in this column
     */
    public TableComparator (int columnIndex, String compareType) {
        myColumnIndex = columnIndex;
        myType = compareType;
    }

    @Override
    /**
     * compare two Data
     */
    public int compare (ArrayList<Comparable> o1, ArrayList<Comparable> o2) {
        Data d1 = new Data(o1.get(myColumnIndex), myType);
        Data d2 = new Data(o2.get(myColumnIndex), myType);
        return d1.compareTo(d2);
    }
}
